package BLL;

import DAL.LogDao;
import DAL.ReaderDao;
import DAL.ReaderTypeDao;
import Entity.Reads;

import java.util.Date;
import java.util.List;

/**
 * 读者信息增删改查
 *
 * @Author Chen
 * @Date 2022/1/6 19:19
 * @Version 1.0
 */
public class ReaderService {
    private static LogDao ld=new LogDao();
    private static ReaderDao readerDao = new ReaderDao();
    private static ReaderTypeDao readerTypeDao = new ReaderTypeDao();

    public static int addReader(Object... args) {
        int result = readerDao.addReader(args);
        Date date=new Date();
        String s="添加了读者信息！";
        ld.insertloginLog(date,s);
        return result;
    }


    public static int deleteReader(Object... args) {
        int result = readerDao.deleteReader(args);
        Date date=new Date();
        String s="删除了读者信息！";
        ld.insertloginLog(date,s);
        return result;
    }


    public static int updateReader(Object... args) {
        int result = readerDao.updateReader(args);
        Date date=new Date();
        String s="修改了读者信息！";
        ld.insertloginLog(date,s);
        return result;
    }


    public static void selectAllReader() {
        List<Reads> result = readerDao.selectAllReader();
        if (result.size() != 0) {
            System.out.println("ID" + "\t读者姓名" + "\t性别" + "\t年龄" + "\t所在单位" + "\t电话" + "\t注册时间" + "\t读者类型名称" + "\t借阅本数" + "\t可最大借阅天数");
            for (int i = 0; i < result.size(); i++) {
                System.out.println((i + 1)
                        + result.get(i).toString());
            }
            Date date=new Date();
            String s="查询了读者信息！";
            ld.insertloginLog(date,s);
        } else {
            System.out.println("暂无数据！！！");
        }
    }


    public static Reads selectReaderById(Object... args) {
        Reads reader = null;
        if ((reader = readerDao.selectReaderById(args)) != null) {
            Date date=new Date();
            String s="根据编号查询了读者信息！";
            ld.insertloginLog(date,s);
            return reader;
        }
        return null;
    }


    public  static List<Reads> selectReaderByName(Object... args) {
        List<Reads> readers ;
        if ((readers =(List<Reads>) readerDao.selectReaderByName(args))!=null){
            Date date=new Date();
            String s="根据名称查询了读者信息！";
            ld.insertloginLog(date,s);
            return readers;
        }
        return null;
    }


    public static List<Reads> selectReaderType(Object... args) {
        List<Reads> readers;
        if ((readers =(List<Reads>) readerDao.selectReaderType(args))!=null){
            Date date=new Date();
            String s="根据读者类别查询了读者信息！";
            ld.insertloginLog(date,s);
            return readers;
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(selectReaderType(1));
    }
}
